FROM gauss-openeuler-os:22.03
ARG GAUSS_VERSION

# LANG should keep align with value in `locale` character set.
ENV LANG=C.UTF-8

ENV GAUSSHOME=/opt/openGauss
ENV GAUSSDATA=/opt/data/openGauss
ENV GAUSSLOG=/opt/data/gausslog

#OpenGauss Version Information in env
ENV GAUSS_VERSION=${GAUSS_VERSION}

ENV GPHOME=${GAUSSHOME}/om
#At present, CM_HOME and GAUSSHOME can't be decoupled
#ENV CM_HOME=${GAUSSHOME}/cm
ENV CM_HOME=${GAUSSHOME}

# Customized directories
ENV SHARED_VOLUME=/opt/data/volume

# USER omm has been created in OS dockerfile image
RUN set -eux; \
    mkdir -p ${GAUSSHOME} && \
    mkdir -p ${GAUSSDATA} && \
    chmod -R 755 ${GAUSSDATA} && \
    chown -R omm:omm ${GAUSSDATA}

ADD opengauss-${GAUSS_VERSION} ${GAUSSHOME}
ADD om-${GAUSS_VERSION} ${GPHOME}
ADD cm-${GAUSS_VERSION} ${CM_HOME}


# Repair permission with USER=root for cm and gaussdb binaries.
#    mkdir /home/omm/.ssh && \ 
RUN set -eux; \
    cd ${GAUSSHOME}; \
    chmod -R +rx {bin,lib,share,dependency,upgrade_sql}  om/{lib,script} ${CM_HOME}/{bin,lib,tool}  && \ 
    chmod -R +rx *.sh && \ 
    chmod -R +r etc version.cfg opengauss_lite.conf share ${GPHOME}/version.cfg ${CM_HOME}/share && \
    chmod -x bin/*.conf ${GPHOME}/script/config && \
    mkdir -p ${GAUSSDATA} ${SHARED_VOLUME} ${GAUSSLOG} && \ 
    mkdir /home/omm/.ssh && \ 
    chmod 700 /home/omm/.ssh && \
    chmod -R 755 ${GAUSSDATA} && \
    chown -R omm:omm ${GAUSSDATA} ${GAUSSHOME} ${GAUSSLOG} /home/omm/.ssh

ADD entrypoint.sh /entrypoint.sh
ADD generatexml.py /generatexml.py

ADD install.sh /install.sh
ADD lib.sh /opt/lib.sh
ADD generateconf.py /opt/generateconf.py
ADD templates /opt/templates

USER omm 

# Install jinja2 for generateconf
RUN pip3 install jinja2
# need to initialize in entrypoint.sh
# RUN set -eux; \
#     mkdir -p ${CMA_CONF} && \
#     mkdir -p ${CMS_CONF} && \
#     chmod -R 700 ${GAUSS_CM_DIR}

WORKDIR ${GAUSSDATA}
